﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using UnityEngine.Events;



/// <summary>
/// 两个物体靠近事件
/// </summary>
public class DistanceEvent : MonoBehaviour 
{
    //抛出的事件，对外接口
    public  UnityEvent OnNearEvent;
    public float distance=1;
    private bool hasInvoke=true;
    public Transform isClosingTarget;

    void Update()
    {
        float _distance = Vector3.Distance(transform.position, isClosingTarget.position);

        if (_distance < this.distance&&hasInvoke==true)
        {
            Debug.Log("Reached");
            if (OnNearEvent != null)
            {
                OnNearEvent.Invoke();
            }
           
            hasInvoke = false;
        }
    }



}
